﻿
param(
    [parameter(Mandatory = $true)]
    [String]$Server,
    [parameter(Mandatory = $true)]
    [String]$ChildPath,
    [parameter(Mandatory = $true)]
    [String]$ParentPath,
    [Switch]$force=$true
)

$ImageManagementServiceName = "Msvm_ImageManagementService"

$HyperVNamespace = "Root\Virtualization"

$ImageManagementService = Get-WmiObject -ComputerName $Server -Namespace  $HyperVNamespace -Class $ImageManagementServiceName

Write-Debug "child VHD Path = $ChildPath"
Write-Debug "Parent VHD path = $ParentPath"

$ReconnectJob = $ImageManagementService.ReconnectParentVirtualHardDisk($ChildPath,$ParentPath,$force) 

#Very parent path of the differencing disk is updated correctly
$VHDInfo = $ImageManagementService.GetVirtualHardDiskInfo($ChildPath)
if($VHDInfo -ne $null)
{
    return $VHDInfo.ParentPath -eq $ParentPath 
}